#include<bits/stdc++.h>
using namespace std;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int main()
{
	close();
    string a,b;
    cin >> a >> b;
    int n = a.size() ,m = b.size();
    int i = 0, j = 0;
    for( ;i < n && j < m;i ++)//拿a与b匹配
    {
        if(a[i] == b[j]) j ++;
    }
    cout << j << endl;

    return 0;
}